<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 文章功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * @author   create by allen.qiang
 */

quanli_require('module/base/content/contentArticle.class.php');

class pa_articles {

    public function execute() {

        if (isset($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //文章分类列表
                    $this->getArticleList();
                    break;

                case 2: //新增、修改文章
                    $this->editArticle();
                    break;

                default:
                    backendError();
                    break;

            }
        } else {

            backendError();

        }
    }

    /**
     * 文章列表
     */
    private function getArticleList () {

        global $G_PGLOB;

        //实例文章类
        $contentArticle = new contentArticle();

        //查询文章分类
        $arg_array = array(
            'sortname' => 'category_id',
            'sortorder' => 'DESC'
        );
        $category_array = $contentArticle->searchArticleCategory( $arg_array );
        $G_PGLOB->smarty->assign_by_ref('category_array', $category_array);

        $G_PGLOB->smarty->assign('edit_permission', $G_PGLOB->has_permission(1575));

        $G_PGLOB->smarty->display('content/articlesList.tpl');

    }

    /**
     * 新增、修改文章
     */
    private function editArticle() {

        global $G_PGLOB;

        //实例文章类
        $contentArticle = new contentArticle();

        //查询文章分类
        $arg_array = array(
            'useFlg' => 1,
            'sortname' => 'category_id',
            'sortorder' => 'DESC'
        );
        $category_array = $contentArticle->searchArticleCategory( $arg_array );
        if (!$category_array) {
            backendError('文章分类信息没有找到，请先添加文章分类');
        }
        $G_PGLOB->smarty->assign_by_ref('category_array', $category_array);

        if (isset($_REQUEST['article_id']) && quanli_is_int($_REQUEST['article_id'])) {

            //查询文章信息
            $arg_array = array(
                'article_id' => $_REQUEST['article_id']
            );
            $article_array = $contentArticle->searchArticle( $arg_array );
            if (!$article_array) {
                backendError('文章信息没有找到');
            }

            $G_PGLOB->smarty->assign_by_ref('article_array', $article_array[0]);

        }


        $G_PGLOB->smarty->assign('userFlg', 2);

        $G_PGLOB->smarty->display('content/articlesAdd.tpl');

    }

}